<?php
/**
 * Game_Battle_Exploration
 *
 * Класс Game_Battle_Exploration отвечает за разведку
 *
 * @author Дмитрий Кузьма <kouzma.d@gmail.com>
 * @version 1.0
 */
class Game_Battle_Exploration extends Game_Battle_Battle {
	
	protected static $_availableBattleTypes = array('exploration');
	
	const BASE_ATTACK_POINTS = 35;
	const BASE_DEFENSE_POINTS = 20;

	/**
	 * (non-PHPdoc)
	 * @see Game_Battle_Battle::_getWinnerPowCoeff()
	 */
	protected function _getWinnerPowCoeff() {
		return 1.5;
	}
	
	/**
	 * Задает очки в сражении
	 */
	protected function _setBattlePoints() {
		// Подсчитываем очки атаки
		$this->_attackPoints = 0;
		$arrUnitsInfo = Game_Unit::getAllUnitsInfo();
		foreach ($this->_arrSentUnits as $arrSentUnit) {
			$unitId = $arrSentUnit['ID_unit'];
			if ($arrUnitsInfo[$unitId]['is_exploration']) {
				$bonusAttack = Game_Unit::getUnitUpgradeBonus(
						self::BASE_ATTACK_POINTS,
						$arrUnitsInfo[$unitId]['consumption_1'],
						$arrSentUnit['unit_level']
				);
				$this->_attackPoints += (self::BASE_ATTACK_POINTS + $bonusAttack) * $arrSentUnit['amount'];
			}
		}
	
		$this->_defensePoints = 0;
		// Подсчитываем очки защиты
		foreach ($this->_arrDefenderUnits as $arrDefenderUnit) {
			$unitId = $arrDefenderUnit['ID_unit'];
			if ($arrUnitsInfo[$unitId]['is_exploration']) {
				$bonusDefense = Game_Unit::getUnitUpgradeBonus(
						self::BASE_DEFENSE_POINTS,
						$arrUnitsInfo[$unitId]['consumption_1'],
						$arrDefenderUnit['unit_level']
				);
				$this->_defensePoints += (self::BASE_DEFENSE_POINTS + $bonusDefense) * $arrDefenderUnit['amount'];
			}
		}
	
		// Добавляем коэффициент морали
		$moraleCoeff = $this->_getMoraleCoeff($this->_attackPoints, $this->_defensePoints);
		$this->_defensePoints *= $moraleCoeff;
		
	}
	
	/**
	 * Задает смерти
	 */
	protected function _setDies() {
		foreach ($this->_arrSentUnits as &$arrAttackerUnit) {
			$arrAttackerUnit['amount_died'] = round($arrAttackerUnit['amount'] * $this->_attackerDiedPart);
		}
	}
}
?>